﻿using System.Drawing.Imaging;
using System.Text;
using Spire.Xls;

namespace EPPlus_ExcelDemo
{
    public static class Conversion
    {
        public static void ConvertToCsv(string input, string output)
        {
            Workbook wb = new Workbook();
            wb.LoadFromFile(input, ExcelVersion.Version2010);
            for (int i = 0; i < wb.Worksheets.Count; i++)
            {
                wb.Worksheets[i].SaveToFile(string.Format("{0}-{1}.csv", output, i), ",", Encoding.UTF8);
            }
        }

        public static void ConvertToImage(string input, string output)
        {
            Workbook wb = new Workbook();
            wb.LoadFromFile(input, ExcelVersion.Version2010);
            for (int i = 0; i < wb.Worksheets.Count; i++)
            {
                wb.Worksheets[i].SaveToImage(string.Format("{0}-{1}.png", output, i), ImageFormat.Png);
            }
        }

        public static void ConvertToPdf(string input, string output)
        {
            Workbook wb = new Workbook();
            wb.LoadFromFile(input, ExcelVersion.Version2010);
            wb.SaveToFile(output, FileFormat.PDF);
        }

        public static void ConvertToXls(string input, string output)
        {
            Workbook wb = new Workbook();
            wb.LoadFromFile(input, ExcelVersion.Version2010);
            wb.SaveToFile(output, ExcelVersion.Version97to2003);
        }

        public static void ConvertToXml(string input, string output)
        {
            Workbook wb = new Workbook();
            wb.LoadFromFile(input, ExcelVersion.Version2010);
            wb.SaveAsXml(output);
        }

    }
}
